<template>
	<view class="template-order tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed customBack :bottomShadow="false" backgroundColor="#16171D">
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left-arrow'></text>
			</view>
			<view class="tn-flex tn-flex-col-center tn-flex-row-center">
				<text class="tn-text-xl tn-color-white">我的盲盒</text>
			</view>
		</tn-nav-bar>

		<view class="" v-if="content.length>0" :style="{paddingTop: vuex_custom_bar_height  +'px'}">
			<view v-for="(item,index) in content" :key="index" class="order__item" >
				<view class="order__item__head tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between">
					<view class="order__item__head__title">
						<text class="">盲盒编号：BOX-2023012{{item.id}}</text>
					</view>
				</view>

				<view
					class="order__item__content tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
					<view class="tn-flex tn-flex-nowrap tn-flex-direction-row tn-flex-col-center tn-flex-row-left">
						<view class="order__item__content__image">
							<image :src="item.coverimage" mode="aspectFill"></image>
						</view>
						<view class="order__item__content__title">
							{{item.name}}
						</view>
					</view>
					<view
						class="order__item__content__info tn-flex tn-flex-direction-column tn-flex-col-center tn-flex-row-center">
						<view class="order__item__content__info__price">
							<text class="order__item__content__info__price--unit  tn-icon-alien"></text>
							<text class="order__item__content__info__price__value--integer">{{item.pay}}</text>
						</view>

					</view>
				</view>

				<view
					class="order__item__operation tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
					<view class="order__item__operaation__left tn-text-sm" style="opacity: 0.5;">
						<text class="tn-icon-time tn-padding-right-xs"></text>
						<text class="">{{item.ctime}}</text>
					</view>
					<view v-if="item.status==0"
						class="order__item__operation__right tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-right">
						<view class="order__item__operation__right__button">
							<tn-button backgroundColor="#FFFFFF" padding="10rpx 18rpx" height="auto" width="100%" @click="hui(item)"
								:fontSize="22" :plain="true" fontColor="#FFFFFF" shape="round">
								盲盒回收
							</tn-button>
							
						</view>
					</view>
					<view v-if="item.status==0"
						class="order__item__operation__right tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-right">
						<view class="order__item__operation__right__button">
							<tn-button backgroundColor="#FFFFFF" padding="10rpx 18rpx" height="auto" width="100%"  @click="tn(item)"
								:fontSize="22" :plain="true" fontColor="#FFFFFF" shape="round">
								填写发货地址
							</tn-button>
							
						</view>
					</view>
					<view v-if="item.status==1"
						class="order__item__operation__right tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-right">
						<view class="order__item__operation__right__button">
							<tn-button backgroundColor="#FFFFFF" padding="10rpx 18rpx" height="auto" width="100%"
								:fontSize="22" :plain="true" fontColor="#FFFFFF" shape="round">
								已核销
							</tn-button>
							
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="" v-if="content.length==0">
			<view class="" style="padding: 15vh 20rpx;opacity: 0.6;">
				<view class="tn-text-center" style="font-size: 260rpx;padding-top: 30rpx;">
					<text class="tn-icon-order tn-color-gray--light"></text>
				</view>
				<view class="tn-color-gray--disabled tn-text-center tn-text-lg">暂无盲盒信息~~~</view>
			</view>
		</view>
		<view class='tn-tabbar-height'></view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {
		name: 'TemplateOrder',
		mixins: [template_page_mixin],
		data() {
			return {
				content: [],
				page: 1,
			}
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			// 跳转
			tn(item) {
				uni.navigateTo({
					url: '../boxdetails/boxdetails?id='+item.goodsid+'&boxid='+item.id,
				});
			},
			getlist() {
				let than = this;
				this.$http.postRequest('BlindBoxUser/BoxList', {
						page: this.page
					})
					.then(res => {
						if (res.data.length > 0) {
							than.page = than.page + 1;
							let arr = res.data;
							arr.forEach(function(item, index, array) {
								than.content.push(item)
							})
						}

					})
			},
			hui(item){
				let than=this;
				uni.showModal({
					title:"盲盒回收提醒",
					content:"对兑等价U币:"+item.pay+" ？",
					success: function (res) {
						if (res.confirm) {
							than.$http.postRequest('BlindBoxUser/Hui', {
									id: item.id
								})
								.then(res => {
									than.content=[]
									than.page=1
									than.getlist()
								})
						} else if (res.cancel) {
							console.log("用户取消操作");
						}
					}
				})
			}
			
		},
		// 滚动到底部
		onReachBottom(e) {
			this.getlist()
		}
	}
</script>

<style lang="scss" scoped>
	.template-order {}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 40rpx;
		height: calc(60rpx + env(safe-area-inset-bottom) / 2);
		height: calc(60rpx + constant(safe-area-inset-bottom));
	}

	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 60%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 100rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

	}

	.top-fixed {
		position: fixed;
		top: 0;
		width: 100%;
		transition: all 0.25s ease-out;
		z-index: 100;
	}


	.order {
		&--wrap {
			position: fixed;
			left: 0;
			right: 0;
			width: 100%;
			background-color: inherit;
		}

		/* 导航栏 start */
		&__tabs {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			background-color: inherit;
		}

		/* 导航栏 end */

		/* 订单内容 start */
		&__item {
			color: #FFFFFF;
			margin: 30rpx;
			padding: 36rpx 26rpx;
			border-radius: 15rpx;
			border: 1rpx solid #494B51;
			background-color: rgba(255, 255, 255, 0.08);
			border-radius: 15rpx;
			// box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);

			&:first-child {
				margin-top: 40rpx;
			}

			&:last-child {
				margin-bottom: 0;
			}

			/* 头部 start */
			&__head {

				&__title {
					font-weight: bold;
					line-height: normal;

					&--right-icon {
						font-size: 24rpx;
						margin-left: 8rpx;
					}
				}

				&__status {
					font-size: 22rpx;
					color: #AAAAAA;
				}
			}

			/* 头部 end */

			/* 内容 start */
			&__content {

				margin-top: 20rpx;

				&__image {
					margin-right: 20rpx;

					image {
						width: 140rpx;
						height: 140rpx;
						border-radius: 10rpx;
					}
				}

				&__title {
					padding-right: 40rpx;
					display: -webkit-box;
					overflow: hidden;
					white-space: normal !important;
					text-overflow: ellipsis;
					word-wrap: break-word;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				&__info {

					&__price {
						&--unit {
							font-size: 20rpx;
						}

						&__value--integer,
						&__value--decimal {
							font-weight: bold;
						}

						&__value--decimal {
							font-size: 20rpx;
						}
					}

					&__count {
						color: #AAAAAA;
						font-size: 24rpx;
					}
				}
			}

			/* 内容 end */

			/* 操作按钮 start */
			&__operation {
				margin-top: 20rpx;

				&__right {
					&__button {
						margin-left: 10rpx;
					}
				}
			}

			/* 操作按钮 end */
		}

		/* 订单内容 end */
	}
</style>